package com.ruoyi.system.mapper.HUAWEI;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.system.domain.HUAWEI.AtLockedItemInfoTi;
import com.ruoyi.system.domain.HUAWEI.AtLockedItemInfoTiRecord;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 华为隔离锁定清单Mapper接口
 *
 * @author ruoyi
 * @date 2023-03-25
 */
public interface AtLockedItemInfoTiMapper extends BaseMapper<AtLockedItemInfoTi> {

    @Select("select *\n" +
            "                      from (\n" +
            "                               select psw.*,ROW_NUMBER() over (partition by trans_id ORDER BY updated_date desc) rown\n" +
            "                               from AT_LOCKED_ITEM_INFO_TI psw \n" +
            "                               ) a\n" +
            "                      where a.rown = 1 and updated_date>='2023-09-26 00:28:16'")
    List<AtLockedItemInfoTi> selectDistin();


    @Select("select * from(select *,ROW_NUMBER() over(order by trans_id)as 'atid' from AT_LOCKED_ITEM_INFO_TI) as a where a.atid between 0 and 5000")
    List<AtLockedItemInfoTiRecord> selectDistinPc();


    @Select("select top 10000 * from AT_LOCKED_ITEM_INFO_TI_Record t where t.status=0 and xf_time is null")
    List<AtLockedItemInfoTiRecord> selectDistinRecord();


    @Update("update AT_LOCKED_ITEM_INFO_TI_Record set status=1,xf_time=GETDATE() where trans_id=#{transId} and updated_date=#{updateDate}")
    int updateByRecord(@Param("transId") String transId, @Param("updateDate") String updateDate);

    @Delete("delete from AT_LOCKED_ITEM_INFO_TI_Record where status=1 and trans_id=#{transId}")
    void deleteByRecord(@Param("transId")String transId);
}
